/* ===========================
   GLOBAL STYLES & RESET
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow-x: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ===========================
   MAIN CONTAINER
   Adapts height based on context
   =========================== */
#mainContainer {
    width: 100%;
    height: 450px; /* Default for iframe */
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
}

/* Detect if opened in new tab (not in iframe) */
@media all and (min-height: 500px) {
    body:not(.in-iframe) #mainContainer {
        height: 90vh;
    }
}

/* ===========================
   TOOLTIP STYLES
   =========================== */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 1000;
    max-width: 250px;
    text-align: center;
    line-height: 1.4;
}

.tooltip.show {
    opacity: 1;
}

#headerTooltip {
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
}

/* ===========================
   INTERACTIVE PANEL
   =========================== */
#interactivePanel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===========================
   KEYBOARD SECTION
   =========================== */
#keyboardSection {
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#keyboardSVG {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
}

/* Piano key styles applied via JavaScript */
.piano-key {
    transition: fill 0.1s, stroke 0.1s;
    cursor: pointer;
}

.piano-key.white {
    fill: #ffffff;
    stroke: #333;
    stroke-width: 1.5;
}

.piano-key.black {
    fill: #222;
    stroke: #000;
    stroke-width: 1;
}

.piano-key.active {
    fill: #4CAF50 !important;
}

.piano-key:hover {
    opacity: 0.8;
}

#playInstruction {
    text-align: center;
    font-size: 12px;
    color: #666;
    margin-top: 6px;
}

/* ===========================
   WAVEFORM VISUALIZATION
   =========================== */
#visualizationSection {
    background: #1a1a2e;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    position: relative;
}

#waveformCanvas {
    width: 100%;
    height: 80px;
    display: block;
    border-radius: 4px;
}

#waveformLabel {
    text-align: center;
    color: #fff;
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.8;
}

/* ===========================
   CONTROLS SECTION
   =========================== */
#controlsSection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 10px;
}

/* Effect Group */
.effect-group {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: transform 0.2s, box-shadow 0.2s;
}

.effect-group:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.effect-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.effect-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.effect-toggle {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #667eea;
}

.effect-name {
    user-select: none;
}

.info-icon {
    font-size: 16px;
    cursor: help;
    color: #667eea;
    transition: transform 0.2s;
}

.info-icon:hover {
    transform: scale(1.2);
}

/* Effect Controls */
.effect-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 28px;
}

.control-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-row label {
    font-size: 12px;
    color: #555;
    display: flex;
    justify-content: space-between;
}

/* Slider Styles */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: background 0.3s;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.slider:active::-webkit-slider-thumb {
    transform: scale(1.25);
}

.slider:active::-moz-range-thumb {
    transform: scale(1.25);
}

/* Action Buttons */
#actionButtons {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-btn {
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    min-height: 44px;
    white-space: nowrap;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.action-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* ===========================
   ANALYTICS PANEL
   =========================== */
#analyticsPanel {
    background: #f1f3f5;
    border-top: 2px solid #dee2e6;
    display: flex;
    flex-direction: column;
    max-height: 180px;
    transition: max-height 0.3s ease;
}

#analyticsPanel.collapsed {
    max-height: 40px;
}

#analyticsHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #e9ecef;
    cursor: pointer;
    user-select: none;
}

#analyticsTitle {
    font-weight: 600;
    font-size: 13px;
    color: #495057;
}

#analyticsControls {
    display: flex;
    gap: 8px;
}

.analytics-btn {
    padding: 4px 10px;
    font-size: 11px;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 28px;
}

.analytics-btn:hover {
    background: #f8f9fa;
}

.analytics-btn:active {
    background: #e9ecef;
}

#analyticsContent {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
}

#analyticsPanel.collapsed #analyticsContent {
    display: none;
}

#actionLog {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #333;
    line-height: 1.6;
}

.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid #e9ecef;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-timestamp {
    color: #6c757d;
    font-weight: 600;
}

.log-action {
    color: #495057;
}

.log-value {
    color: #667eea;
    font-weight: 600;
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (max-width: 768px) {
    #interactivePanel {
        padding: 8px;
        gap: 8px;
    }

    #controlsSection {
        grid-template-columns: 1fr;
    }

    .effect-group {
        padding: 8px;
    }

    #actionButtons {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
    }

    #analyticsPanel {
        max-height: 150px;
    }
}

/* ===========================
   ACCESSIBILITY
   =========================== */
button:focus,
input:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Ensure minimum touch target size */
button,
input[type="checkbox"],
.slider {
    min-height: 44px;
    min-width: 44px;
}

input[type="checkbox"] {
    min-width: 20px;
    min-height: 20px;
}

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.effect-group.active {
    animation: pulse 0.5s ease;
}